<template>
    <div id="QADetail">
        <div>
            <h1 class="text-success">{{title}}</h1>
        </div>
        <hr>
        <div >
            <span class="text-success mr-2">日期: {{date}}</span>
            <span class="text-success mr-2">应用模块: {{model}}</span>
            <span class="text-success mr-2">项目: {{project}}</span>
            <span class="text-success mr-2">过滤条件一: {{select1}}</span>
            <span class="text-success">过滤条件二: {{select2}}</span>
        </div>

        <tablegerritinfo v-if="model==='gerrit'" :date="date" :filter1="select1" :filter2="select2"></tablegerritinfo>

        <div class="row" v-if="model==='bugzilla'">
            <div class="col-lg-12">
                <DataTable :table_id="tableinfo_newcreatebug.id" :table_title="tableinfo_newcreatebug.title" :columns="tableinfo_newcreatebug.columns" 
                    :table_data='tableinfo_newcreatebug.table_data' :columns_key="tableinfo_newcreatebug.columns_key" :columnDefs="tableinfo_newcreatebug.columnDefs">  
                </DataTable>
            </div>
            <div class="col-lg-12">
                <DataTable :table_id="tableinfo_fixedbug.id" :table_title="tableinfo_fixedbug.title" :columns="tableinfo_fixedbug.columns" 
                    :table_data='tableinfo_fixedbug.table_data' :columns_key="tableinfo_fixedbug.columns_key" :columnDefs="tableinfo_fixedbug.columnDefs">  
                </DataTable>
            </div>
            <div class="col-lg-12">
                <DataTable :table_id="tableinfo_closedbug.id" :table_title="tableinfo_closedbug.title" :columns="tableinfo_closedbug.columns" 
                    :table_data='tableinfo_closedbug.table_data' :columns_key="tableinfo_closedbug.columns_key" :columnDefs="tableinfo_closedbug.columnDefs">  
                </DataTable>
            </div>
            <div class="col-lg-12">
                <DataTable :table_id="tableinfo_legacybug.id" :table_title="tableinfo_legacybug.title" :columns="tableinfo_legacybug.columns" 
                    :table_data='tableinfo_legacybug.table_data' :columns_key="tableinfo_legacybug.columns_key" :columnDefs="tableinfo_legacybug.columnDefs">  
                </DataTable>
            </div>
            <div class="col-lg-12">
                <DataTable :table_id="tableinfo_personalbug.id" :table_title="tableinfo_personalbug.title" :columns="tableinfo_personalbug.columns" 
                    :table_data='tableinfo_personalbug.table_data' :columns_key="tableinfo_personalbug.columns_key" :columnDefs="tableinfo_personalbug.columnDefs">  
                </DataTable>
            </div>
        </div>
        
        
    </div>
</template>
<script>
import DataTable from '@/components/qa/DataTable.vue'
import TableGerritInfo from '@/components/qa/QADetail/TableGerritInfo.vue'
export default {
    name: 'QADetail',
    components: {
        tablegerritinfo:TableGerritInfo,
        DataTable,
    },
    props: {
        
    },
    data() {
        return {
            date: '',
            model: '',
            title: '',
            tableinfo_gerrit: {
                columnDefs: [
                    {
                        targets: 9,
                        // eslint-disable-next-line 
                        render: function(data, type, row, meta) {
                            var gerrit_url = row.gerrit_url
                            return '<a href="'+gerrit_url
                                +'" class="btn btn-sm btn-primary"  target="_blank">查看详情</a>';
                        }
                    }
                ]
            },
            tableinfo_legacybug: {
                id: 'table_defect_legacybug',
                title: '遗留缺陷数据',
                columns: ['创建日期','提交单号','标题','版本号','模块名称','创建者', '指派给', '指派日期', '截止期限', '操作'],
                table_data: [],
                columns_key: [
                    {data: 'b_createtime', width: '10%'},
                    {data: 'b_number'},
                    {data: 'b_summary'},
                    {data: 'b_version'},
                    {data: 'b_component'},
                    {data: 'b_creator',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    }, 
                    {data: 'b_assigned_to',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    },
                    {data: 'b_assignedtime'},
                    {data: 'b_deadline'}
                ],
                columnDefs: [
                    {
                        targets: 9,
                        width: '10%',
                        // eslint-disable-next-line 
                        render: function(data, type, row, meta) {
                            var ticket_no = row.b_number
                            return '<a href="http://192.168.100.160/html/bugzilla/show_bug.cgi?id='+ticket_no
                                +'" class="btn btn-sm btn-primary" target="_blank">查看详情</a>';
                        }
                    }
                ],
            },
            tableinfo_newcreatebug: {
                id: 'table_defect_newcreatebug',
                title: '新增缺陷数据',
                columns: ['创建日期','提交单号','标题','版本号','模块名称','创建者', '指派给', '指派日期', '截止期限', '操作'],
                table_data: [],
                columns_key: [
                    {data: 'b_createtime', width: '10%'},
                    {data: 'b_number'},
                    {data: 'b_summary'},
                    {data: 'b_version'},
                    {data: 'b_component'},
                    {data: 'b_creator',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    }, 
                    {data: 'b_assigned_to',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    },
                    {data: 'b_assignedtime'},
                    {data: 'b_deadline'}
                ],
                columnDefs: [
                    {
                        targets: 9,
                        width: '10%',
                        // eslint-disable-next-line 
                        render: function(data, type, row, meta) {
                            var ticket_no = row.b_number
                            return '<a href="http://192.168.100.160/html/bugzilla/show_bug.cgi?id='+ticket_no
                                +'" class="btn btn-sm btn-primary" target="_blank">查看详情</a>';
                        }
                    }
                ],
            },
            tableinfo_fixedbug: {
                id: 'table_defect_fixedbug',
                title: '已解决缺陷数据',
                columns: ['解决日期','提交单号','标题','版本号','模块名称','创建者', '指派给', '指派日期', '截止期限', '操作'],
                table_data: [],
                columns_key: [
                    {data: 'b_resolvedtime', width: '10%'},
                    {data: 'b_number'},
                    {data: 'b_summary'},
                    {data: 'b_version'},
                    {data: 'b_component'},
                    {data: 'b_creator',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    }, 
                    {data: 'b_assigned_to',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    },
                    {data: 'b_assignedtime'},
                    {data: 'b_deadline'}
                ],
                columnDefs: [
                    {
                        targets: 9,
                        width: '10%',
                        // eslint-disable-next-line 
                        render: function(data, type, row, meta) {
                            var ticket_no = row.b_number
                            return '<a href="http://192.168.100.160/html/bugzilla/show_bug.cgi?id='+ticket_no
                                +'" class="btn btn-sm btn-primary" target="_blank">查看详情</a>';
                        }
                    }
                ],
            },
            tableinfo_closedbug: {
                id: 'table_defect_closedbug',
                title: '已关闭缺陷数据',
                columns: ['关闭日期','提交单号','标题','版本号','模块名称','创建者', '指派给', '指派日期', '截止期限', '操作'],
                table_data: [],
                columns_key: [
                    {data: 'b_closedtime', width: '10%'},
                    {data: 'b_number'},
                    {data: 'b_summary'},
                    {data: 'b_version'},
                    {data: 'b_component'},
                    {data: 'b_creator',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    }, 
                    {data: 'b_assigned_to',
                    // eslint-disable-next-line
                     render: function( data, type, row, meta) {
                         var arr = data.split('@')
                         return arr[0]+'\n'+'@'+arr[1]
                     }
                    },
                    {data: 'b_assignedtime'},
                    {data: 'b_deadline'}
                ],
                columnDefs: [
                    {
                        targets: 9,
                        width: '10%',
                        // eslint-disable-next-line 
                        render: function(data, type, row, meta) {
                            var ticket_no = row.b_number
                            return '<a href="http://192.168.100.160/html/bugzilla/show_bug.cgi?id='+ticket_no
                                +'" class="btn btn-sm btn-primary" target="_blank">查看详情</a>';
                        }
                    }
                ],
            },
            tableinfo_personalbug: {
                id: 'table_defect_personalbug',
                title: '个人缺陷消减',
                columns: ['指派日期', '指派给', '数量'],
                table_data: [],
                columns_key: [
                    {data: 'date'},
                    {data: 'b_assigned_to'},
                    {data: 'b_number__count'},
                ],
                columnDefs: [],
            },
        }
    },
    methods: {
        getLegacyBugInfo: function(after, before, project, branch, component) {
            this.$axios.get('/api/qa/legacybug/?after='+after+'&before='+before+'&project='+project+'&branch='+branch+'&component='+component)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.summary);
                        this.tableinfo_legacybug.table_data = response.data.legacybug;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getNewCreateBugInfo: function(after, before, project, branch, component) {
            this.$axios.get('/api/qa/newcreatebug/?after='+after+'&before='+before+'&project='+project+'&branch='+branch+'&component='+component)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.summary);
                        this.tableinfo_newcreatebug.table_data = response.data.newcreatebug;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getFixedBugInfo: function(after, before, project, branch, component) {
            this.$axios.get('/api/qa/fixedbug/?after='+after+'&before='+before+'&project='+project+'&branch='+branch+'&component='+component)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.summary);
                        this.tableinfo_fixedbug.table_data = response.data.fixedbug;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getClosedBugInfo: function(after, before, project, branch, component) {
            this.$axios.get('/api/qa/closedbug/?after='+after+'&before='+before+'&project='+project+'&branch='+branch+'&component='+component)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.summary);
                        this.tableinfo_closedbug.table_data = response.data.closedbug;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
        getPersonalBugInfo: function(after, before, project, branch, component) {
            this.$axios.get('/api/qa/personalbug/?after='+after+'&before='+before+'&project='+project+'&branch='+branch+'&component='+component)
                .then((response) => {
                    if (response.status == 200) {
                        // eslint-disable-next-line
                        // console.log(response.data.summary);
                        this.tableinfo_personalbug.table_data = response.data.personalbug;
                    }
                })
                .catch(function(err) {
                    // eslint-disable-next-line
                    console.log(err);
                });
        },
    },
    created: function() {
        this.date = this.$route.params.date;
        this.model = this.$route.params.model;
        this.project = this.$route.params.pmsProjectId;
        this.select1 = this.$route.params.select1;
        this.select2 = this.$route.params.select2;
        console.log(this.date, this.model, this.project, this.select1, this.select2);
    },
    mounted: function() {
        var after = '';
        var before = '';
        var time = '';
        var select2 = this.select2;
        if (this.select2 =='nullstring') {
            select2 = '';
        }
        if (this.date == 'nullString') {
            
        } else if (this.date.length == 10) {
            time = this.date + ',' + this.date;
        } else {
            time = this.date;
        }
        if (this.model=='gerrit') {
            this.title = '代码评审数据汇总详情';
            // this.getGerritInfo(this.project, time, this.select1, select2);
        }
        else if (this.model=='bugzilla') {
            this.title = '缺陷分析数据汇总详情';
            this.getLegacyBugInfo(after, before, this.project, this.select1, select2);
            this.getNewCreateBugInfo(after, before, this.project, this.select1, select2);
            this.getFixedBugInfo(after, before, this.project, this.select1, select2);
            this.getClosedBugInfo(after, before, this.project, this.select1, select2);
            this.getPersonalBugInfo(after, before, this.project, this.select1, select2);
        }
        
    }
}
</script>
